package com.easybuy.controller;

import com.easybuy.Tools.Page;
import com.easybuy.service.CategoryService.CategoryService;
import com.easybuy.service.ProductService.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class BrandlistController {
    @Autowired
    private ProductService productService;
    @Autowired
    private CategoryService categoryService;

    @RequestMapping("/selectProducts")
    @ResponseBody
    //查询id分类下的所有商品（分页）
    public Page selectProducts(@RequestParam int id,@RequestBody Page page){
        Map map=new HashMap();
        map.put("id",id);
        map.put("page",page);
        page=productService.selectProducts(map);;
        return page;
    }
    @RequestMapping("/levels")
    @ResponseBody
    //查询该分类和其所有父分类名称
    public List levels(@RequestParam int id){
        List level=new ArrayList();
        level=categoryService.selectNames(id);
        return level;
    }
}
